﻿/*----------------------------------------------------------------
  //Copyright (C) 2012 赵国伟
  //文件功能描述：我的购物车
  //创建人：赵国伟
  //生成时间：2012/03/17 16:15:00
//----------------------------------------------------------------*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using Shopping.Common;
using Shopping.Model;
using Shopping.BLL;

public partial class Home_ShoppingCarts : BasePage
{
    private readonly ShoppingCartsManage bllCarts = new ShoppingCartsManage();
    private readonly GoodsManage bllGoods = new GoodsManage();

    protected List<ShoppingCartInfo> listOfCarts;
    protected int totalQuantity;
    protected decimal totalMoney;

    protected string backUrl = "";

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            int GoodsID = Utility.G<int>("GoodsID"); //获取商品ID;
            int PackUnitID = Utility.G<int>("PackUnitID"); //获取包装ID;
            int Quantity = Utility.G<int>("Quantity");
            if (Quantity <= 0)
                Quantity = 1;
            backUrl = Utility.G("BackUrl"); //获取返回地址；

            if (GoodsID > 0)
            {
                GoodsInfo g = bllGoods.GetGoods(GoodsID);
                if (PackUnitID <= 0) PackUnitID = g.BaseInfo.PackUnitID;

                ShoppingCarts d = new ShoppingCarts();
                d.CreateDate = DateTime.Now;
                d.GoodsID = GoodsID;
                d.PackUnitID = PackUnitID;
                d.CookiesID = bllCarts.GetShoppingCartCookieName(this.UserID);
                d.Discount = 1.00M;
                d.PresentScores = g.BaseInfo.GiveScores * Quantity;
                d.Price = g.BaseInfo.SalePrice;
                d.Quantity = Quantity;
                bllCarts.Save(d);
                Response.Redirect("/Home/ShoppingCarts.aspx");
                Response.End();
            }

            //加载购物车中的数据；
            listOfCarts = bllCarts.QueryList(bllCarts.GetShoppingCartCookieName(this.UserID));
        
        }
    }
}